<template>
  <div>
    <div p-5>
      <TaskInfo :id="route.query.id"></TaskInfo>
      <div class="taskInfo-body-box">
        <div class="taskInfo-body-box-tittle">
          <div class="taskInfo-body-box-tittle-left"></div>
          <div class="taskInfo-body-box-tittle-right">文书制作</div>
        </div>
        <div class="taskInfo-body-box-info">
          <a-row :gutter="24">
            <a-col class="gutter-row" :span="8">
              <BookCreate :type="18" :id="id" :url="taskData?.fileUrl" @getBookUrl="getBookUrl" />
            </a-col>
          </a-row> </div
      ></div>
    </div>
    <div class="bottomBox"></div>
    <div class="bottomBtns" style="z-index: 3">
      <a-space :size="12">
        <a-button size="large" @click="cacel">取消</a-button>
        <a-button size="large" type="primary" @click="onSubmit">提交</a-button>
      </a-space>
    </div>
    <a-modal title="记录表编号设置" v-model:open="open" :width="400" @ok="handleOk">
      <BeCurrent ref="administrativePenalty" @getDataUrl="getDataUrl" />
    </a-modal>
  </div>
</template>
<script setup lang="ts">
  import { useRoute } from 'vue-router';
  import TaskInfo from './components/taskInfo.vue';
  import BookCreate from '@/components/basic/book-create/index.vue';
  import router from '@/router';
  import { onMounted, reactive, ref } from 'vue';
  import { message } from 'ant-design-vue';
  import BeCurrent from '@/components/basic/book-create/components/beCurrent/index.vue';
  import { processRoutineTask, taskrcxfInfo } from '@/api/routine';
  import { useTabsViewStore } from '@/store/modules/tabsView';
  const tabsViewStore = useTabsViewStore();
  const route = useRoute();
  const cacel = () => {
    router.back();
  };
  const open = ref(false);

  const id = route.query.id as any;

  const getBookUrl = (data) => {
    console.log(data);
    if (data.code == 0) {
      taskrcxfInfoApi();
    }
  };

  const onSubmit = () => {
    taskrcxfInfoApi();
    if (taskData.value?.fileUrl != '') {
      open.value = true;
    } else {
      message.error('文书未制作！');
    }
  };

  const taskData = ref();

  const taskrcxfInfoApi = async () => {
    const data = await taskrcxfInfo(route.query.id);
    taskData.value = data;
  };
  const administrativePenalty = ref();
  const handleOk = () => {
    administrativePenalty.value.confirm();
  };
  const getDataUrl = async (data) => {
    console.log(data);
    let params = {
      id: id,
      ...data,
    };
    const res = await processRoutineTask(0, params);
    if (res.code == 0) {
      message.success('提交成功！');
      tabsViewStore.closeCurrentTabToUrl(route, '/routine/routine/routineFirePatrol');
      open.value = false;
    }
  };

  onMounted(async () => {
    if (route.query.id) {
      taskrcxfInfoApi();
    }
  });
</script>
<style lang="less" scoped>
  .taskInfo {
    &-body {
      &-box {
        margin-bottom: 16px;
        &-tittle {
          display: flex;
          align-items: center;
          padding: 13px 0 13px 0;
          &-left {
            border: 1px solid #0f53ac;
            margin-right: 7px;
            border-radius: 4px;
            height: 14px;
          }

          &-right {
            font-size: 16px;
            font-weight: 400;
            line-height: 24px;
            color: rgba(68, 68, 68, 1);
          }
        }
      }
    }
  }
</style>
